import com.newland.flow.model.NodeModel;
import com.newland.flow.view.BaseNodeView;

import flash.events.MouseEvent;
import flash.ui.Mouse;

import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.controls.Menu;
import mx.controls.MenuBar;
import mx.controls.menuClasses.MenuBarItem;
import mx.core.UIComponent;
import mx.events.MenuEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;

[Bindable]
public var menuBarCollection:XMLListCollection;

private var menubarXML:XMLList = 
	<>
		<menuitem label="文件" data="top">
			<menuitem label="新建" data="create" enabled='true' />
			<menuitem label="打开" data="open" enabled='true' />
			<menuitem label="删除" data="delete" enabled='false' />
        	<menuitem label="保存" data="save" enabled='true'/>
			<menuitem label="关闭" data="close" enabled='true'/>
		</menuitem>
	</>;

public function menuHandler(event:MenuEvent):void {
	var item:String = event.item.@data ;
	if(item == "create") {
		
	}
	if(item == "open") {
		
	}
	if(item == "save") {
		
	}
	if(item == "delete") {
		
	}
	if(item == "close") {
		
	}
}

/**工具栏动作**/
public function saveHandler(event:MouseEvent):void {
	var modelCollection:ArrayCollection = new ArrayCollection();
	if(processModule.nodeCollection != null && processModule.nodeCollection.length >0) {
		for(var n:Number=0;n<processModule.nodeCollection.length;n++) {
			var node:BaseNodeView = processModule.nodeCollection.getItemAt(n) as BaseNodeView;
			var model:NodeModel = new NodeModel();
			model.id = node.id;
			model.id = node.id;
			model.nodeName = node.nodeName;
			model.x = node.x;
			model.y = node.y;
			model.nodeType = node.nodeType;
			if(node.linkToCollection!=null && node.linkToCollection.length>0) {
				for(var m:Number=0;m<node.linkToCollection.length;m++) {
					model.nextNodes.addItem(UIComponent(node.linkToCollection.getItemAt(m)).id);
				}
			}
			modelCollection.addItem(model);
		}
	}
	var remote:RemoteObject = new RemoteObject();
	remote.destination = "xml";
	remote.saveAsXml(modelCollection);
	remote.addEventListener(ResultEvent.RESULT,saveResult);
	remote.addEventListener(FaultEvent.FAULT,fault);
}
private function saveResult(event:ResultEvent):void {}
private function fault(event:FaultEvent):void {}